package cn.szzsi._webpc;

import cn.szzsi.common.kit.BackUtil;
import cn.szzsi.common.kit.CommonUtil;
import cn.szzsi.common.model.Member;
import cn.szzsi.common.model.Tocash;
import cn.szzsi.common.model.UserBalance;
import cn.szzsi.common.sms.SmsEmayUtil;
import cn.szzsi.service.UserBalanceService;
import com.jfinal.captcha.CaptchaRender;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.ehcache.CacheKit;
import org.apache.commons.codec.binary.Base64;

import java.util.List;

public class UserBalanceController extends BaseWebPcController<UserBalance>{

    public void index(){
        Member member = getLoginMember();
        setAttr("member",member);
        setAttr("balance", UserBalanceService.service.getBalance(member));

        List<Tocash> toCashingList= Tocash.getByMemberId(member.getStr("id"));
        setAttr("toCashingList",toCashingList);
        pcTemplatePath("member_deposit_detail.html");
    }


    public void validateCaptcha() {
        String phone = getPara("phone");
        //同一个手机号限制一分钟之内只能发送一条
        Long lastTimeMillis = CacheKit.get("sms_last_time",phone);
        if(lastTimeMillis!=null){
            Long currentTimeMillis=System.currentTimeMillis();
            if((currentTimeMillis-lastTimeMillis)<60000){
                renderJson(Ret.fail("info","您的操作过于频繁,请稍后再试!!"));
                return;
            }

        }

        //【微米荟商城】您的验证码:686260 ，请勿泄露！感谢您的使用！
        String captcha = CommonUtil.getSixRandom();//六位纯数字验证码
        String message = "【微米荟商城】您的验证码:"+captcha+" ，请勿泄露！感谢您的使用！";
        boolean sendResult= SmsEmayUtil.sendToSms("0",phone,message,"yzm","wmh",captcha);
        if(sendResult){
            renderJson(BackUtil.success("发送成功"));
        }else{
            renderJson(BackUtil.fail("发送成功"));
        }
    }


}
